﻿using StockHelper.Scripts.Comm;
using StockHelper.Scripts.Sound;
using StockHelper.Scripts.Stock;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StockHelper.Scripts
{
    public class Start
    {
        

        public static void Init() {

            Config.Init();
            StockCtrl.Init();
            CheckTime();
            Comm.Timer.Start();


            Config.voiceTime = Config.Get("voiceTime", Config.voiceTime);
            Config.playVoice = Config.Get("noPlayVoice", "0") != "1";
            Config.voiceVolume = Config.Get("voiceVolume", Config.voiceVolume);
            if (Config.Get("topMost/show", "0") == "1")
                new TopMostBox().Show();
        }

        public static void CheckTime()
        {
            int time0 = Time.GetStartTime();
            int time1 = 3600 * 1 + (30 * 60) + time0;
            int time2 = 3600 * 3 + (30 * 60) + time0;
            int time3 = 3600 * 5 + time0;
            int time4 = 3600 * 7 + time0;
            int now = Time.GetTimeStamp();

            if (Comm.Time.GetWeek() > 0 && Comm.Time.GetWeek() < 6)
            {
                if (now < time1)
                {
                    Comm.Timer.Add(CheckTime, time1);
                }
                else if (now < time2)
                {
                    if (Config.playVoice)
                        Comm.Timer.Add(StockHelper.Scripts.Sound.VoicePlay.Play, now + Config.voiceTime, Config.voiceTime);
                    Comm.Timer.Add(Stock.StockCtrl.GetNewData, now + Config.updataTime, Config.updataTime);
                    Comm.Timer.Add(CheckTime, time2);
                }
                else if (now >= time2 && now < time3)
                {
                    Comm.Timer.Add(CheckTime, time3);
                }
                else if (now < time4)
                {
                    if (Config.playVoice)
                        Comm.Timer.Add(StockHelper.Scripts.Sound.VoicePlay.Play, now + Config.voiceTime, Config.voiceTime);
                    Comm.Timer.Add(Stock.StockCtrl.GetNewData, now + Config.updataTime, Config.updataTime);
                }
                else if (now >= time4)
                {
                    Comm.Timer.Add(CheckTime, 3600 * 24 + Time.GetStartTime());
                }
            }
            else
            { //周六周日
                Comm.Timer.Add(CheckTime, 3600 * 24 + Time.GetStartTime());
            }



        }


























    }
}
